package com.ruoyi.kjgl.service.impl;

import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.kjgl.mapper.KjspMapper;
import com.ruoyi.kjgl.domain.Kjsp;
import com.ruoyi.kjgl.service.IKjspService;

/**
 * 砍价商品Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-05
 */
@Service
public class KjspServiceImpl implements IKjspService 
{
    @Autowired
    private KjspMapper kjspMapper;

    /**
     * 查询砍价商品
     * 
     * @param id 砍价商品主键
     * @return 砍价商品
     */
    @Override
    public Kjsp selectKjspById(Long id)
    {
        Kjsp kjsp = kjspMapper.selectKjspById(id);
        String wlfsStr = kjsp.getWlfsStr();
        String[] split = wlfsStr.split(",");
        kjsp.setWlfs(Arrays.asList(split));
        return kjsp;
    }

    /**
     * 查询砍价商品列表
     * 
     * @param kjsp 砍价商品
     * @return 砍价商品
     */
    @Override
    public List<Kjsp> selectKjspList(Kjsp kjsp)
    {
        return kjspMapper.selectKjspList(kjsp);
    }

    /**
     * 新增砍价商品
     * 
     * @param kjsp 砍价商品
     * @return 结果
     */
    @Override
    public int insertKjsp(Kjsp kjsp)
    {
        List<String> wlfs = kjsp.getWlfs();
        String join = String.join(",", wlfs);
        kjsp.setWlfsStr(join);
        return kjspMapper.insertKjsp(kjsp);
    }

    /**
     * 修改砍价商品
     * 
     * @param kjsp 砍价商品
     * @return 结果
     */
    @Override
    public int updateKjsp(Kjsp kjsp)
    {
        return kjspMapper.updateKjsp(kjsp);
    }

    /**
     * 批量删除砍价商品
     * 
     * @param ids 需要删除的砍价商品主键
     * @return 结果
     */
    @Override
    public int deleteKjspByIds(Long[] ids)
    {
        return kjspMapper.deleteKjspByIds(ids);
    }

    /**
     * 删除砍价商品信息
     * 
     * @param id 砍价商品主键
     * @return 结果
     */
    @Override
    public int deleteKjspById(Long id)
    {
        return kjspMapper.deleteKjspById(id);
    }
}
